package com.gdufs.secondhandwebsite.controller;

import com.gdufs.secondhandwebsite.dao.TagMapper;
import com.gdufs.secondhandwebsite.entity.Goods;
import com.gdufs.secondhandwebsite.entity.GoodsType;
import com.gdufs.secondhandwebsite.entity.Post;
import com.gdufs.secondhandwebsite.entity.Tag;
import com.gdufs.secondhandwebsite.util.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Api(tags = "二手交易网站帖子标签类相关接口")
@RestController
@RequestMapping("tag")
public class TagController extends BaseController{
    @Autowired
    TagMapper tagMapper;

    @ApiOperation(value = "获取帖子标签一级类别")
    @PostMapping("tagtype")
    public JsonResult<List<Tag>> getByTypeName(String tagtype) {
        List<Tag> result =tagMapper.SelectByTagType(tagtype);
        JsonResult jsonResult = new JsonResult<List<Tag>>(OK);
        jsonResult.setData(result);
        return  jsonResult;
    }

    @ApiOperation(value = "获取所有帖子标签")
    @GetMapping("all")
    public JsonResult<List<String>> getPostAll(){
        List<String> result =tagMapper.getAll();
        JsonResult jsonResult = new JsonResult<List<String>>(OK);
        jsonResult.setData(result);
        return  jsonResult;
    }

    @ApiOperation(value = "根据标签id获取帖子标签")
    @PostMapping("get_by_id")
    public JsonResult<List<Tag>> getById(Integer tagId) {
        Tag result =tagMapper.getTagByTagId(tagId);
        JsonResult jsonResult = new JsonResult<List<Tag>>(OK);
        jsonResult.setData(result);
        return  jsonResult;
    }
}
